﻿/*版权声明
 * 
 * 本 河北大学管理学院信息管理系网站 由
 * 河北大学 信管团队 开发
 * 如有任何疑问请联系开发人员
 * 
 * 项目开发者：朱胜贤、孙旭峰、水亚亚、张文元、项玥、吕芳、吴凡、谢静、李亚慧
 * 
 * 如有任何疑问请联系：河北大学信管团队
 * QQ：196396337
 * Email:zagelover@163.com
 * HomePage：http://sxgzs.com/
 * 
 * CopyRight (c) 河北大学信管团队 2010~2020
 */

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Admin_Intro_Add : System.Web.UI.Page
{
    /// <summary>页面加载事件
    /// 	<remark>2010-10-21 河北大学信管团队-朱胜贤 </remark>
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        //检查用户权限
        if (Session["Uid"] == null)
        {
            //无权限返回登录页
            Response.Redirect("AD_Login.aspx");
            return;
        }
        //情况消息框
        lblMessage.Text = "";
        if (!IsPostBack)
        {
            //提取URL传参
            string ID = Request.QueryString["ID"].ToString();
            if (ID == "")
            {//如果参数为空
                lblTitle.Text = "添加信管系简介";
                btnCancel.Text = "清空";
            }
            else
            {//如果参数不为空
                lblTitle.Text = "编辑信管系简介";
                Bind_Txt(ID);
            }
        }
    }

    /// <summary>绑定数据——文本框
    /// 	<remark>2010-10-23 河北大学信管团队-朱胜贤 </remark>
    /// </summary>
    private void Bind_Txt(string ID)
    {
        //定义sql语句
        string sql = "select * from Department_Info where depID=@depID";
        //定义参数
        SqlParameter[] para = { new SqlParameter("@depID", SqlDbType.Int) };
        //参数赋值
        para[0].Value = ID;
        //取得数据
        SqlDataReader DR = DataAccess.GetReader(sql, para);
        if (DR.HasRows)
        {//如果有数据
            while (DR.Read())
            {//显示数据
                ViewState["ID"] = ID;
                txtTitle.Text = DR["depTitle"].ToString();
                txtContent.Text = DR["depContent"].ToString();
                txtNum.Text = DR["depSort"].ToString();
            }
        }
    }

    /// <summary>响应单击按钮事件——添加或者修改记录
    /// 	<remark>2010-10-23 河北大学信管团队-朱胜贤  </remark>
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (lblTitle.Text.Trim() == "添加信管系简介")
        {//如果是添加信息系简介
            //定义sql语句
            string sql = "insert into Department_Info(depTitle,depContent,depSort) values(@depTitle,@depContent,@depSort)";
            //定义参数
            SqlParameter[] para = {
                    new SqlParameter("@depTitle", SqlDbType.NVarChar,50),
                    new SqlParameter("@depContent", SqlDbType.NText),
                    new SqlParameter("@depSort", SqlDbType.TinyInt)};
            //给参数赋值
            para[0].Value = txtTitle.Text.Trim();
            para[1].Value = txtContent.Text;
            para[2].Value = txtNum.Text.Trim();
            if (DataAccess.ExecuteSQL(sql,para))
            {//如果添加成功
                //显示添加成功提示并转到管理页
                Response.Write("<script>alert('添加信息成功！');location.href='Intro_Manage.aspx';</script>");
            }
            else
            {//如果添加失败
                lblMessage.Text = "添加信息失败";
            }
        }
        else if (lblTitle.Text.Trim() == "编辑信管系简介")
        {
            //定义sql语句
            string sql = "update Department_Info set depTitle=@depTitle,depContent=@depContent,depSort=@depSort where depID=@depID";
            //定义参数
            SqlParameter[] para = {
                    new SqlParameter("@depTitle", SqlDbType.NVarChar,50),
                    new SqlParameter("@depContent", SqlDbType.NText),
                    new SqlParameter("@depSort", SqlDbType.TinyInt),
                    new SqlParameter("@depID", SqlDbType.Int)};
            //给参数赋值
            para[0].Value = txtTitle.Text.Trim();
            para[1].Value = txtContent.Text;
            para[2].Value = txtNum.Text.Trim();
            para[3].Value = ViewState["ID"].ToString();
            if (DataAccess.ExecuteSQL(sql, para))
            {//如果修改成功
                Response.Write("<script>alert('修改信息成功！');location.href='Intro_Manage.aspx';</script>");
            }
            else
            {//如果修改失败
                lblMessage.Text = "修改信息失败";
            }
        }
    }

    /// <summary>响应单击按钮事件——清空或取消
    /// 	<remark>2010-10-23 河北大学信管团队-朱胜贤  </remark>
    /// </summary>
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        if (lblTitle.Text.Trim() == "添加信管系简介")
        {
            txtTitle.Text = "";
            txtNum.Text = "0";
            txtContent.Text = "";
        }
        else if (lblTitle.Text.Trim() == "编辑信管系简介")
        {
            //转到新管理简介管理界面
            Response.Redirect("Intro_Manage.aspx");
        }
    }

}
